package com.six.elemo_manger.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.avos.avoscloud.AVObject;
import com.bumptech.glide.Glide;
import com.six.elemo_manger.R;
import com.six.elemo_manger.bean.FoodList;

import java.util.List;

public class OnlineAdapter extends BaseAdapter {
    private List<FoodList> list;
    private Context context;

    public OnlineAdapter(List<FoodList> list, Context context) {
        this.list = list;
        this.context = context;
        Log.d("执行了Adapter","adapter");
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHoder viewHolder;
        Log.d("执行了getView","adapter");
        //如果view未被实例化过，缓存池中没有对应的缓存
        if (convertView == null) {
            viewHolder = new ViewHoder();
            // 由于我们只需要将XML转化为View，并不涉及到具体的布局，所以第二个参数通常设置为null
            convertView = View.inflate(context, R.layout.item_online, null);

            //对viewHolder的属性进行赋值

            viewHolder.tv_online_name = (TextView) convertView.findViewById(R.id.tv_online_name);
            viewHolder.img_online = (ImageView) convertView.findViewById(R.id.img_online);
            viewHolder.tv_online_price = (TextView) convertView.findViewById(R.id.tv_online_price);

            //通过setTag将convertView与viewHolder关联
            convertView.setTag(viewHolder);
        }else{//如果缓存池中有对应的view缓存，则直接通过getTag取出viewHolder
            viewHolder = (ViewHoder) convertView.getTag();
        }
        // 取出bean对象

        // 设置控件的数据
       // Glide.with(context).load(list.get(position).getString("food_Img")).into(viewHolder.img_online);
       // viewHolder.tv_online_name.setText(list.get(position).getString("food_Name"));
       // viewHolder.tv_online_name.setText(list.get(position).getString("food_Price"));


        return convertView;
    }
    class ViewHoder{
        private TextView tv_online_name,tv_online_price;
        private ImageView img_online;

    }
}
